﻿using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static SerialPortTest.Serial_cfg;

namespace SerialPortTest
{
    class Program : ISerialRecv
    {
        public static readonly Program Ins = new Program();

        static void Main(string[] args)
        {
            Ins.Load();
        }
        SerialTool _com_tool;

        private void Load()
        {
            _com_tool = new SerialTool();
            var com1_cfg = new Serial_cfg();
            com1_cfg.PortID = SerialPortEnum.com7;
            com1_cfg.BaudRate = SerialBoundRate.BR4800;
            com1_cfg.DataBits = SerialDataBits.DB8;
            com1_cfg.Party = Parity.None;
            com1_cfg.StopBits = StopBits.One;
            _com_tool.Init(this, com1_cfg);

            _com_tool.Open();
        }



        public void On_serial_recved(byte[] buff, Serial_cfg cfg)
        {
            if (cfg == null || buff == null)
                return;

            switch (cfg.PortID)
            {
                case SerialPortEnum.com1:
                    Console.WriteLine("com1  rcved data. len:" + buff.Length);
                    break;
                case SerialPortEnum.com2:
                    break;
                case SerialPortEnum.com3:
                    break;
                case SerialPortEnum.com4:
                    break;
                case SerialPortEnum.com5:
                    break;
                case SerialPortEnum.com6:
                    break;
                case SerialPortEnum.com7:
                    break;
                case SerialPortEnum.com8:
                    break;
                case SerialPortEnum.max_com_val:
                    break;
                default:
                    break;
            }
        }
    }
}
